#!/usr/bin/env python
# -*- coding: utf-8 -*-
# author:Charles.chen
# createDate:2017/9/5
# Title:
# Tip:
from flask import render_template, redirect, request, url_for, flash, session
from flask_login import login_user, logout_user, login_required, current_user
from . import auth, authService
from app.toolkit import commonUtil
import json

@auth.route('/login', methods=['GET', 'POST'])
def login():
    reponse = {}
    reponse["status"] = 0
    if request.method == 'POST':
        post_data = json.loads(request.data)
        login_account = post_data['login_account']
        login_pwd = post_data['login_pwd']
        user = authService.getUserByAccountAndPwd(login_account, login_pwd)
        if user is not None:
            login_user(user, True)
            return commonUtil.buildSucc('/guide/welcome')
        else:
            return commonUtil.buildErr("no user")
    return render_template('/auth/login.html')

# 执行登出操作
@auth.route('/logout', methods=['GET'])
def logout():
    session.clear()
    logout_user()
    return redirect(url_for('loginIndex'))






if __name__ == '__main__':
    pass